package com.yidi.system;

import com.yidi.common.annotation.RepeatSubmit;
import com.yidi.system.domain.SysNotice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.yidi.common.annotation.Log;
import com.yidi.common.core.controller.BaseController;
import com.yidi.common.core.domain.AjaxResult;
import com.yidi.common.core.page.TableDataInfo;
import com.yidi.common.enums.BusinessType;
import com.yidi.system.service.SysNoticeService;

/**
 * @author ：Xn
 * @ClassName: SysNoticeController
 * @date ：2021-10-19 15:06
 * @describe ： 公告 信息操作处理
 */
@RestController
@RequestMapping("/system/notice")
public class SysNoticeController extends BaseController
{
    @Autowired
    private SysNoticeService noticeService;

    /**
     * 获取通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('system:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysNotice notice, @RequestParam(defaultValue = "0") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize)
    {

        Page<SysNotice> findByPage = noticeService.findByPage(pageNum, pageSize, notice);
        return getDataTable(findByPage);
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:notice:query')")
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable Long noticeId)
    {
        return AjaxResult.success(noticeService.findById(noticeId));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@Validated @RequestBody SysNotice notice)
    {
        noticeService.add(notice);
        return success();
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@Validated @RequestBody SysNotice notice)
    {
        noticeService.updateNotice(notice);
        return success();
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:notice:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable Long[] noticeIds)
    {
        noticeService.deleteNoticeByIds(noticeIds);
        return success();
    }
}
